<?php
require_once(CORE_DIR.'Common.php');
require_once(CORE_DIR.'mappers/PointTypeMapper.php');

class pointtypeModel extends Model{
	
	function __construct(){
		$this->conn = $this->getConnection();
	}
	
	function addPointType($typeName, $typeDesc){
		$query = "insert into pointtype (typeName, description)
				  values ('%s', '%s')";
		$query = $this->format($query, array($typeName, $typeDesc));
		$this->execute($query, new PointTypeMapper());			
		return mysqli_insert_id($this->conn);
	}	
	
	function updatePointType($id, $typeName, $typeDesc){
		$query = "update pointtype set typeName='%s', description='%s' where pintTypeID=%d";
		$query = $this->format($query, array($typeName, $typeDesc, $id));		
		return $this->execute($query, new PointTypeMapper());	
	}

	function deletePointType($id){
		$query = "delete from pointtype where pintTypeID=%d";
		$query = $this->format($query, array($id));		
		return $this->execute($query, new PointTypeMapper());
	}		
	
	function getPointTypes(){
		$query = "SELECT * FROM pointtype ORDER BY typeName";		
		return $this->execute($query, new PointTypeMapper());		
	}
	
	function getPointTypesById($id){
		$query = "SELECT * FROM pointtype WHERE pintTypeID=%d";
		$query = $this->format($query, array($id));		
		return $this->execute($query, new PointTypeMapper());
	}	
	
}
?>
